import numpy as np
from scipy import sparse

# 科学计算中的 数组
x = np.array([[0,2,0],[0,5,0], [0,0,1]])

print(f"x={x}")

spa = sparse.csc_matrix(x)
print(f"CSR:\n{spa}")

y = np.array([7,8,9])

print(f"y={y}")

# 创建一个二维numPy数组，对角线为1，其余为0
eye = np.eye(4)
print(f"NumPy array:\n{eye}")
# 将numPy转为CSR格式的Scipy稀疏矩阵
sparse_matrix = sparse.csr_matrix(eye)
print(f"sparse CSR:\n{sparse_matrix}")


# COO格式
data = np.ones(4)
row_indices = np.arange(4)
col_indices = np.arange(4)
eye_coo = sparse.coo_matrix((data, (row_indices, col_indices)))
print(f'COO data:\n{eye_coo}')